$(document).ready(function () {
    $("#submit").click(function () {
        $.ajax({
            url: '/login',
            type: 'post',
            data: {
                username: $("#username").val(),
                password: $("#password").val()
            },
            dataType: 'json',
            success: function (data) {
                document.cookie = 'token=' + data.data + '; path=/'
                console.log(data.code)
                if (data.code === 200) {
                    window.location.href='../index.html'
                    console.log("登录成功")
                } else {
                    window.location.href='../login.html'
                    console.log("登录失败")
                }
            },
            error: function () {
                console.log('Error occurred while fetching JSON data.')
            }
        })
    })
})
